<template>
	<view >
		<view class="flex align-c nav" :style="{paddingTop: statusBar + 'px'}">
			<image src="/static/home/back.png" mode="widthFix" class="nav_back_icon" @click="$back" />
			<view class="f1">
				<view class="nav_seach_box flex align-c">
					<image src="/static/home/seach-icon-gray.png" mode="aspectFill" class="nav_seach_icon" />
					<input type="text" class="input-box" placeholder-class="p-c" v-model="keyword" placeholder="搜索用户昵称">
				</view>
			</view>
		</view>
		
		<view class="between align-c tabs" :style="{top: statusBar+ 44 + 'px'}">
			<view class="tabs_item" v-for="(v,i) in navdatas" :key="i" @click="checkNav(v.type)">
				<view class="item-name" :class="{'act': status === v.type}" >{{ v.name }}</view>
				<view class="tabs_line" :class="{'tabs_line_act': status === v.type}"></view>
			</view>
		</view>
		
		<view :style="{height: statusBar + 88 +'px'}" />
		
		<view class="course" v-for="(v,i) in list" :key="i">
			<view class="course_top flex align-c">
				<view class="f1 flex align-c">
					<image v-if="v && v.user && v.user.avator" :src="$img(v.user.avator)" mode="aspectFill" class="course_top_img" />
					<image v-else src="/static/head.png" mode="aspectFill" class="course_top_img" />
					<view v-if="v && v.user && v.user.name">{{ v.user.name }}</view>
					<view v-else></view>
				</view>
				<view class="course_top_status" :class="{'red': v.status < 4}">{{ v.state }}</view>
			</view>
			<view class="course_content flex">
				<image v-if="v && v.course && v.course.cover" :src="$img(v.course.cover)" mode="aspectFill" class="course_content_img" />
				<view class="f1">
					<view class="fw-b" v-if="v && v.course && v.course.title">{{ v.course.title }}</view>
					<view class="course_content_label" v-if="v && v.course && v.course.start_at">单次价格：{{ v.course.price }}/次</view>
					<view class="course_content_label" v-if="status == 3">购买课次：<text style="color: red;">{{ v.used }}</text> /{{v.number}}</view>
					<view class="course_content_label" v-else>购买课次：{{v.number}}</view>
				</view>
			</view>
			<view class="course_bottom flex align-c" v-if="v.status != 2">
				<!-- <button class="btn" v-if="v.status == 2 || v.status == 3" @click="backMoney(v.id)">退款</button> -->
				<button class="btn" v-if="v.status == 3" @click="woffrecord(v.id)">核销记录</button>
				<button class="btn" v-if="v.status == 5" @click="toDetail(v.course.id)">查看详情</button>
			</view>
		</view>
		
		<u-popup :show="show" :round="10" mode="bottom" @close="close" @open="open">
			<view class="item_box">
				<view class="item" v-for="(item,index) in type" :key="index" @click="checkType(item)">{{ item.name }}</view>
				<view class="item_red" @click="close">取消</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBar: 0,
				keyword: '',
				navdatas: [
					{
						name: '全部',
						type: ''
					}, {
						name: '已支付',
						type: 2,
					}, {
						name: '核销中',
						type: 3,
					}, {
						name: '已完成',
						type: 4,
					},
				],
				status: '',
				list: [],
				show: false,
				type: '',
				page: 1,
			}
		},
		onLoad(opt) {
			if(opt.type) {
				this.status = parseInt(opt.type);
			}else {
				this.status = '';
			}
			this.getSystemInfo();
			this.shop_id = uni.getStorageSync('shopId');
		},
		onShow() {
			this.getPrivateOrder();
		},
		methods: {
			getSystemInfo() {
				uni.getSystemInfo({
					success: (e) => {
						this.statusBar = e.statusBarHeight
					}
				})
			},
			checkNav(i){
				this.page = 1;
				this.status= i;
				this.getPrivateOrder();
			},
			reject(){
				uni.navigateTo({
					url:'/pages/messagemodel/reject'
				})
			},
			open() {
				this.show = true;
			},
			close() {
				this.show = false;
			},
			checkType(v) {
				this.typeIndex = v.type;
				this.show = false;
			},
			async getPrivateOrder() {
				let res = await this.$api.get('staff/order/course/list',{
					shop_id: this.shop_id,
					status: this.status,
				});
				if(res.code == 200) {
					this.list = res.data.data;
				}
			},
			backMoney(id){
				this.$to(`/pages/refund/refund?id=${id}`)
			},
			woffrecord(id){
				this.$to(`/pages/home/private/Write-off_record?id=${id}`)
			},
			toDetail(id){
				this.$to(`/pages/home/overt/course_detail?id=${id}`)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.nav {
		font-size: 24rpx;
		background-color: #FFF;
		height: 44px;
		line-height: 44px;
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		z-index: 999;
		&_back_icon {
			width: 15rpx;
			height: 27rpx;
			margin-left: 27rpx;
			margin-right: 20rpx;
		}
		&_seach_box {
			background-color: #F5F5F5;
			border-radius: 30rpx;
			padding: 12rpx 36rpx;
			margin: 0 27rpx;
			margin-left: 20rpx;
		}
		.input-box {
			font-size: 27rpx;
			flex: 1;
			margin: 0 20rpx;
		}
		&_seach_icon {
			width: 25rpx;
			height: 25rpx;
		}
		&_filter {
			width: 29rpx;
			height: 29rpx;
			margin-right: 10rpx;
			margin-left: 80rpx;
		}
		&__class__type {
			justify-content: flex-end;
			margin-right: 20rpx;
		}
	}

	.tabs {
		background-color: #FFF;
		height: 44px;
		line-height: 44px;
		padding: 0 40rpx;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		z-index: 999;
		&_item {
			font-size: 27rpx;
			color: #B3B3B3;
		}
		.item-name {
			line-height: 54rpx;
		}
		.act {
			color: #F17816;
		}
		&_line {
			height: 7rpx;
			background: #ffffff;
			width: 53rpx;
			bottom: 2px;
			border-radius: 100px;
			transition-property: transform;
			transition-duration: 300ms;
			margin: 0 auto;
		}
		&_line_act {
			background-color: #F17816;
		}
	}
	
	.course {
		font-size: 27rpx;
		padding: 0 20rpx;
		background-color: #fff;
		margin: 20rpx 27rpx;
		border-radius: 20rpx;
		&_top {
			padding: 16rpx 0;
			border-bottom: 1rpx solid #F5F5F5;
			&_img {
				width: 47rpx;
				height: 47rpx;
				border-radius: 50%;
				margin-right: 16rpx;
			}
			&_check {
				width: 33rpx;
				height: 33rpx;
				margin-right: 16rpx;
				margin-right: 30rpx;
			}
			&_status {
				color: #B3B3B3;
			}
			.red {
				color: #F51818;
				font-weight: 500;
			}
		}
		&_content {
			padding: 20rpx 0;
			&_img {
				width: 160rpx;
				height: 160rpx;
				border-radius: 10rpx;
				margin-right: 20rpx;
				background-color: #F5F5F5;
			}
			&_label {
				font-size: 24rpx;
				color: #B3B3B3;
				margin-top: 10rpx;
			}
			&_price {
				color: #F51818;
				text-align: right;
				.symbol {
					font-size: 27rpx;
				}
				.fw-b {
					font-size: 32rpx;
				}
				.util {
					font-size: 24rpx;
				}
			}
		}
		&_bottom {
			padding-top: 10rpx;
			padding-bottom: 30rpx;
			justify-content: flex-end;
			.btn {
				margin: 0;
				padding: 0;
				padding: 0 24rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				height: 47rpx;
				line-height: 47rpx;
				min-width: 93rpx;
				text-align: center;
				margin-left: 24rpx;
				background-color: #FFF;
			}
			.org_btn {
				background-color: #F17816;
				color: #fff;
			}
		}
	}
	
	.item_box {
		background-color: #F5F5F5;
		border-radius: 20rpx 20rpx 0 0;
		overflow: hidden;
		.item,.item_red {
			height: 98rpx;
			line-height: 98rpx;
			text-align: center;
			font-size: 32rpx;
			background-color: #FFF;
			border-bottom: 2rpx solid #F5F5F5;
		}
		.item_red {
			color: #F11A1A;
			margin-top: 20rpx;
		}
		.item:last-child {
			border-bottom: none;
		}
	}
</style>